#include "configuremodel.h"
ConfigureModel* ConfigureModel::instance = nullptr;

ConfigureModel *ConfigureModel::getInstance()
{
    if(ConfigureModel::instance == nullptr)
    {
        ConfigureModel::instance = new ConfigureModel;
    }
    return ConfigureModel::instance;
}

int ConfigureModel::InsertConfigure(QString videoPath, QString imagePath, double spaceSize, QString name)
{
    QString sql = QString("insert into tbl_configure(video_path, image_path, space_size, equip_name) values('%1','%2',%3,'%4');").arg(videoPath).arg(imagePath).arg(spaceSize).arg(name);
    int res = SingletonBD::getInstance()->doUpdateInsertDel(sql);
    return res;
}

int ConfigureModel::selectLastConfigure(char **&qres, int &row, int  &col)
{
    QString sql = QString("select equip_name from tbl_configure ORDER BY configure_id DESC LIMIT 1;");

    int res = SingletonBD::getInstance()->doSelect(sql, qres, row, col);
    if(res==0)
        {
            if(row>0)       //有数据   更新设备信息
            {
                qDebug() << "有结果";
                return 0;
            }
        }
    return -1;  //返回默认值
}

int ConfigureModel::selectLastVideoPath(char **&qres, int &row, int &col)
{
    QString sql = QString("select video_path from tbl_configure ORDER BY configure_id DESC LIMIT 1;");

    int res = SingletonBD::getInstance()->doSelect(sql, qres, row, col);
    if(res==0)
        {
            if(row>0)       //有数据   更新设备信息
            {
                qDebug() << "有结果";
                return 0;
            }
        }
    return -1;  //返回默认值
}

int ConfigureModel::selectLastImagePath(char **&qres, int &row, int &col)
{
    QString sql = QString("select image_path from tbl_configure ORDER BY configure_id DESC LIMIT 1;");

    int res = SingletonBD::getInstance()->doSelect(sql, qres, row, col);
    if(res==0)
        {
            if(row>0)       //有数据   更新设备信息
            {
                qDebug() << "有结果";
                return 0;
            }
        }
}

ConfigureModel::ConfigureModel()
{

}
